﻿using System;
using System.Collections.Generic;
using System.Xml;
using YArchitech.Controls;
using YArchitech.LIB;
using YJKAreaStatistic.DataDefine;

namespace YJKAreaStatistic.Manage
{
	internal class XmlManager
	{
		public static bool GetAreaMappingTable(ref Dictionary<string, List<string>> dicResMappingTable)
		{
			try
			{
				XmlElement xmlElement = XmlManager.FindXml();
				if (xmlElement == null)
				{
					YJKMessageBox.Show("初始化用户数据文件(" + XmlManager.m_strFileName + ")失败。");
					return false;
				}
				foreach (object obj in xmlElement.ChildNodes)
				{
					XmlNode xmlNode = (XmlNode)obj;
					List<string> list = new List<string>();
					string attributesValue = XmlManager.GetAttributesValue(xmlNode, "值");
					foreach (object obj2 in xmlNode.ChildNodes)
					{
						string attributesValue2 = XmlManager.GetAttributesValue((XmlNode)obj2, "值");
						if (!string.IsNullOrEmpty(attributesValue2))
						{
							list.Add(attributesValue2);
						}
					}
					if (!dicResMappingTable.ContainsKey(attributesValue))
					{
						dicResMappingTable.Add(attributesValue, list);
					}
				}
			}
			catch (Exception)
			{
				YJKMessageBox.Show("Xml读取失败!");
				return false;
			}
			return true;
		}

		public bool WriteRecordDataToXml(List<RecordCellData> lstDatas)
		{
			return true;
		}

		private static XmlElement FindXml()
		{
			XmlDocument xmlDocument = new XmlDocument();
			XmlElement result;
			try
			{
				string filename = Product.DataLocation + XmlManager.m_strFileName;
				xmlDocument.Load(filename);
				result = xmlDocument.DocumentElement;
			}
			catch (Exception)
			{
				result = null;
			}
			return result;
		}

		private static string GetAttributesValue(XmlNode node, string strAttributes)
		{
			return node.Attributes[strAttributes].Value;
		}

		private static string m_strFileName = "\\面积统计计算公式映射.xml";

		private static string m_strFormDataFileName = "\\AreaStatisticData.xml";
	}
}
